import http from './http.js'

// 权限相关API
export const permissionApi = {
  // 获取所有权限
  getAllPermissions() {
    return http.get('/api/permissions')
  },

  // 根据ID获取权限
  getPermissionById(id) {
    return http.get(`/api/permissions/${id}`)
  },

  // 根据用户ID获取权限
  getPermissionsByUserId(userId) {
    return http.get(`/api/permissions/user/${userId}`)
  },

  // 根据文档ID获取权限
  getPermissionsByDocumentId(documentId) {
    return http.get(`/api/permissions/document/${documentId}`)
  },

  // 根据权限类型获取权限
  getPermissionsByType(type) {
    return http.get(`/api/permissions/type/${type}`)
  },

  // 创建新权限
  createPermission(permissionData) {
    return http.post('/api/permissions', permissionData)
  },

  // 更新权限
  updatePermission(id, permissionData) {
    return http.put(`/api/permissions/${id}`, permissionData)
  },

  // 删除权限
  deletePermission(id) {
    return http.delete(`/api/permissions/${id}`)
  },

  // 批量创建权限
  createBatchPermissions(permissionsData) {
    return http.post('/api/permissions/batch', permissionsData)
  },

  // 批量删除权限
  deleteBatchPermissions(permissionIds) {
    return http.delete('/api/permissions/batch', { ids: permissionIds })
  },

  // 检查用户是否有特定权限
  checkUserPermission(userId, documentId, action) {
    return http.get(`/api/permissions/check/${userId}/${documentId}/${action}`)
  },

  // 授予用户权限
  grantPermission(userId, documentId, action) {
    return http.post('/api/permissions/grant', { userId, documentId, action })
  },

  // 撤销用户权限
  revokePermission(userId, documentId, action) {
    return http.delete('/api/permissions/revoke', { userId, documentId, action })
  }
}
